<script type='text/javascript'>
    $(function() {
        $('#from').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });
    
        
        $('#to').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });

        $('#start_date').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });

        $('#end_date').datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat: 'yy-mm-dd'
        });
    });
</script>	                   
<div class='center_form'>
    <div class="center_form_right">
        <div class='center_form_btn_div' onclick='javascript:Promotion.savePromotion();'>
            <div class='center_form_btn_pic'>
                <img src='<?php echo HttpUtil::baseUrl();?>/images/save.gif'/>
            </div><div class='center_form_btn_text'><?php echo $this->translate("saveBtn"); ?></div>
        </div>        
        <div class='center_form_btn_div' onclick='javascript:Common.gotoUrl("<?php echo HttpUtil::baseUrl();?>/promotion/promotion/coupon");'>
            <div class='center_form_btn_pic'>
                <img src='<?php echo HttpUtil::baseUrl();?>/images/cancel.gif'/>
            </div><div class='center_form_btn_text'><?php echo $this->translate("cancelBtn"); ?></div>
        </div>
    </div>
</div>
<div class="clear"></div>
<div class="centerbig_form">
    <div class="center_top"><span class="center_top_title"><?php echo $this->translate("orderPromotion"); ?></span></div>
    <div class="right_form_content">
        <div class="left_nav_div">
            <div class="left_nav_item_cur" id="left_nav0" onclick="javascript:LeftNav.changeDiv(0,3)"><?php echo $this->translate("editPromotionNav1"); ?></div>
            <div class="left_nav_item" id="left_nav1" onclick="javascript:LeftNav.changeDiv(1,3)"><?php echo $this->translate("editPromotionNav2"); ?></div>
            <div class="left_nav_item" id="left_nav2" onclick="javascript:LeftNav.changeDiv(2,3)"><?php echo $this->translate("editPromotionNav3"); ?></div>
        </div>
        <form action="<?php echo HttpUtil::baseUrl();?>/promotion/promotion/subordercoupon" method="post">
            <input type="hidden" id="blank_error" name="blank_error" value="<?php echo $this->translate("isEmpty"); ?>">
            <input type="hidden" id="same_error" name="same_error" value="<?php echo $this->translate("unique"); ?>">
            <input type="hidden" id="number_error" name="number_error" value="<?php echo $this->translate("notNumber"); ?>">
            <input type="hidden" id="condition_error" name="condition_error" value="<?php echo $this->translate("notRestriction"); ?>">
            <input type="hidden" id="action_error" name="action_error" value="<?php echo $this->translate("notAction"); ?>">
            <input type="hidden" id="baseurl" name="baseurl" value="<?php echo HttpUtil::baseUrl(); ?>">
            <input type="hidden" id="promotiontype" name="promotiontype" value="<?php echo $this->promotionttype; ?>">
            <input type="hidden" id="codeExitInfo" name="codeExitInfo" value="<?php echo $this->translate('codeExitInfo'); ?>" />
            <input type="hidden" id="removeBtn" value="<?php echo $this->translate('remove'); ?>" />
            <input type="hidden" id="promotionActionInfo1" value="<?php echo $this->translate('promotionActionInfo1'); ?>" />
            <input type="hidden" id="promotionActionInfo2" value="<?php echo $this->translate('promotionActionInfo2'); ?>" />
            <input type="hidden" id="cutPercent" value="<?php echo $this->translate('cutPercent'); ?>" />
            <input type="hidden" id="cutAmount" value="<?php echo $this->translate('cutAmount'); ?>" />
            <input type="hidden" id="freeShipping" value="<?php echo $this->translate('freeShipping'); ?>" />
            <input type="hidden" id="noCouponCodeInfo" value="<?php echo $this->translate('noCouponCodeInfo'); ?>" />
            <div class="centerbig_right_nav" id="right_content_div0">
                <div class="form_content">
                  
                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->form->name->getlabel() ?></div>
                        <div class="form_element">
                            <input type="text" value="" id="name" name="name" onblur="javascript:Promotion.validationName('#name',1,'<?php echo HttpUtil::baseUrl();?>');"/>
                            <div class="form_element_error" id="name_error"><?php echo ZendFormUtil::renderErrorMessage($this->form->name);?></div>
                        </div>
                    </div>
                    <div class="clear"></div>

                    <?php ZendFormUtil::renderElement($this->form->show_in_product); ?>

                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->form->short_description->getlabel() ?></div>
                        <div class="form_element">
                            <textarea cols="40" rows="5" id="short_description" name="short_description" onblur="javascript:Promotion.validationShortDescription('#short_description');"></textarea>
                            <div class="form_element_error" id="short_description_error"><?php echo ZendFormUtil::renderErrorMessage($this->form->short_description);?></div>
                        </div>
                    </div>
                    <div class="clear"></div>

                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->form->long_description->getlabel() ?></div>
                        <div class="form_element">
                            <textarea cols="40" rows="5" id="long_description" name="long_description" onblur="javascript:Promotion.validateBlank('#long_description');"></textarea>
                            <div class="form_element_error" id="long_description_error"><?php echo ZendFormUtil::renderErrorMessage($this->form->long_description);?></div>
                        </div>
                    </div>
                    <div class="clear"></div>

                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->translate('from'); ?></div>
                        <div class="form_element">
                            <input type="text" value="" id="from" name="from"  readonly/>
                            <select name="fhour" id="fhour">
                                <?php foreach($this->time['hour'] as $hour) { ?>
                                <option value="<?php echo $hour; ?>"><?php echo $hour; ?></option>
                                <?php } ?>
                            </select> :
                            <select name="fmin" id="fmin">
                                <?php foreach($this->time['min'] as $min) { ?>
                                <option value="<?php echo $min; ?>"><?php echo $min; ?></option>
                                <?php } ?>
                            </select> :
                            <select name="fsec" id="fsec">
                                <?php foreach($this->time['sec'] as $sec) { ?>
                                <option value="<?php echo $sec; ?>"><?php echo $sec; ?></option>
                                <?php } ?>
                            </select>
                            <div class="form_element_error" id="from_error"><?php echo ZendFormUtil::renderErrorMessage($this->form->from);?></div>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->translate('to'); ?></div>
                        <div class="form_element">
                            <input type="text" value="" id="to" name="to" readonly/>
                            <select name="thour" id="thour">
                                <?php foreach($this->time['hour'] as $hour) { ?>
                                <option value="<?php echo $hour; ?>"><?php echo $hour; ?></option>
                                <?php } ?>
                            </select> :
                            <select name="tmin" id="tmin">
                                <?php foreach($this->time['min'] as $min) { ?>
                                <option value="<?php echo $min; ?>"><?php echo $min; ?></option>
                                <?php } ?>
                            </select> :
                            <select name="tsec" id="tsec">
                                <?php foreach($this->time['sec'] as $sec) { ?>
                                <option value="<?php echo $sec; ?>"><?php echo $sec; ?></option>
                                <?php } ?>
                            </select>
                            <div class="form_element_error" id="to_error"><?php echo ZendFormUtil::renderErrorMessage($this->form->to);?></div>
                        </div>
                    </div>
                    <div class="clear"></div>
                    <?php ZendFormUtil::renderElement($this->form->status); ?>
                    <?php ZendFormUtil::renderElement($this->form->auto_apply); ?>
                    <?php ZendFormUtil::renderElement($this->form->uses_per_customer); ?> 
                    <?php ZendFormUtil::renderElement($this->form->uses); ?>
                    <?php ZendFormUtil::renderElement($this->form->stackable); ?>
                    <?php ZendFormUtil::renderElement($this->form->priority); ?>
                    <div class="form_line_div" >
                        <div class="form_element_label"><?php echo $this->translate("couponCode");?></div>
                        <div class="form_element" >
                            <div> 
                                <input type="button" id="add_new_code" value="<?php echo $this->translate("addNewCode");?>" onclick="javascript:Promotion.addNewCode('<?php echo HttpUtil::baseUrl();?>');" />
                                <input type="button" id="remove_selected_code" value="<?php echo $this->translate("removeCode")?>" onclick="javascript:Promotion.removeSelectedCode();" />
                                <input type="hidden" id="code_num" value="1" />
                                <input type="hidden" id="select_code_num" name="select_code_num" value="" />
                            </div>
                            <div>
                               <table id="code_table" class="form_element_table" cellspacing="0" cellpadding="0" >
                                   <thead>
                                   <tr>
                                       <td class="dbgrid_th_ckb"><input type="checkbox" id="select_all_code" name="select_all_code" onclick="javascript:Promotion.selectAllCode(this);"/></td>
                                       <td class="dbgrid_th2" ><?php echo $this->translate('couponCode');?></td>
                                       <td class="dbgrid_th2" style="width:36px;"><?php echo $this->translate('customerId');?></td>
                                       <td class="dbgrid_th2" ></td>
                                   </tr>
                                   </thead>
                                   <tbody>
                                   <tr>
                                       <td class="dbgrid_td_ckb" ><input type="checkbox" id="1" name="select_code" value="1" /></td>
                                       <td class="dbgrid_td" ><input type="text" id="code_input_1" name="code_1" value="<?php echo Number::getGiftCouponCode();?>" onblur="javascript:Promotion.checkCodeUnique(this);"  /><div id="error_code_input_1" class="form_element_error" /></div></td>
                                       <td class="dbgrid_td" ><input type="text" style="width:80px;" id="customerid_input_1" name="customerid_1" /></td>
                                       <td class="dbgrid_td"  ><input type="button" id="button_1" value="<?php echo $this->translate('remove');?>" onclick="javascript:Promotion.removeCode(this);" /></td>
                                   </tr>
                                   </tbody>
                               </table> 
                             </div>
                        </div>
                        <div class="clear"></div>
                      </div>
                      <div class="clear"></div>
                      <div class="form_line_div" style="margin-left: 124px; margin-bottom: 5px;">
                          <div id="couponCodeErrorLabel" class="form_element_label"></div>
                          <div id="couponCodeError" class="form_element_error"></div>
                      </div>
                      <div class="clear"></div>  
                    <div class="form_line_div">
                        <div class="form_element_label"><?php echo $this->translate('pointExchangePromotion'); ?></div>
                        <div class="form_element">
                            <input type="checkbox" id="point_exchange" onclick="javascript:Promotion.pointExchange();" />
                            <input type="hidden" id="point_exchange_select" value="0" name="point_exchange_select" />
                        </div>
                    </div>
                    <div class="clear"></div>
                    <div id="pointExchangeInfo" style="display:none;" >
                        <?php ZendFormUtil::renderElement($this->form->exhaust_point); ?>
                        <?php ZendFormUtil::renderElement($this->form->min_ac_point); ?>
                        <?php ZendFormUtil::renderElement($this->form->start_date); ?>
                        <?php ZendFormUtil::renderElement($this->form->end_date); ?>
                    </div>
                </div>
            </div>



            <div class="centerbig_right_nav" id="right_content_div1" style="display:none">
                <div class="form_content">
                    <!-- department -->
                    <div class="form_line_div">
                        <div class="form_element">
                            <select id="selectRestriction" name="selectRestriction">
                                <?php foreach($this->Restrictiontype as $key => $value) { ?>
                                <option label="ProductRestriction" value="<?php echo $key; ?>"><?php echo $value; ?></option>
                                <?php } ?>
                            </select>
                            <input type="button" name="AddRestriction" value="<?php echo $this->translate('addRestrictionBtn'); ?>" onclick="javascript:Promotion.addRestriction();"/>
                            <div class="form_element_error" id="Restriction_error"></div>
                        </div>
                    </div>
                    <div class='clear'></div>
                </div>

                <div id="restrictions" style="margin-left: 20px;">
                    <input type="hidden" name="selectedRestrictionType" id="selectedRestrictionType" />
                    <div  id="restriction_3" style="border:2px solid #629508;margin-left: 20px;margin-bottom: 20px;margin-right: 20px;display:none;" >
                        <div style="font-size:12px;color:#005A5A;"><span style="float:right;cursor:pointer;" onclick="javascript:Promotion.removeRestriction('restriction_3');"><?php echo $this->translate('close'); ?></span></div>
                        <div style="float: left; padding-top: 2px; margin:15px;">
                            <label class="table_text"><?php echo $this->translate("subtotal"); ?></label>
                            <select id="operator" name="operator">
                                <?php
                                foreach ($this->operator as $key => $operator) {
                                    ?>

                                <option value="<?php echo $key; ?>"><?php echo $operator; ?></option>
                                <?php }?>
                            </select>
                            <input type="text" name="total" id="total" onblur="javascript:Promotion.validateNumber('#total');"/>
                        </div>
                        
                        <div class="form_element_error" id="total_error" style="margin-top:20px;"></div>
                        <div class="clear"></div>
                    </div>
                    <div id="restriction_6"  style="border:2px solid #629508;margin-left: 20px;margin-bottom: 20px;margin-right: 20px;display: none;">
                        <input type="hidden" id="customerRestriction" name="customerRestriction" value="0" /> 
                        <div style="font-size:12px;color:#005A5A;"><span style="float:right;cursor:pointer;" onclick="javascript:Promotion.removeRestriction('restriction_6');"><?php echo $this->translate('close'); ?></span></div>
                        <div>
                            <div style="margin-left:20px;margin-top:20px;">
                                <input type="button" name="SelectCustomer" value="<?php echo $this->translate("selectCustomer"); ?>" onclick="javascript:Promotion.openCustomerDialog('<?php echo HttpUtil::baseUrl();?>');"/>
                                <input type="button" name="remove" value="<?php echo $this->translate("removeCustomer"); ?>" onclick="javascript:Promotion.removeCustomers();"/>
                            </div>
                            <table cellspacing="0" cellpadding="0" class="form_element_table" style="margin-top:5px;margin-left:20px;">
                                <thead>
                                    <tr>
                                        <td class="dbgrid_th_ckb"><input type="checkbox" id="customerAllCkb" onclick="javascript:Promotion.checkCustomerAll();" style="margin-right:0px;"/></td>
                                        <td class="dbgrid_th2"><span><?php echo $this->translate("customerNo"); ?></span></td>
                                        <td class="dbgrid_th2"><span><?php echo $this->translate("username"); ?></span></td>
                                        <td class="dbgrid_th2"><span><?php echo $this->translate("email"); ?></span></td>
                                   </tr>
                                </thead>
                                <tbody id="customerBody">
                                </tbody>
                           </table>
                        </div>
                    </div>
                    
                    
                    
                    <div  id="restriction_8" style="border:2px solid #629508;margin-left: 20px;margin-bottom: 20px;margin-right: 20px;display:none;" >
                        <div style="font-size:12px;color:#005A5A;"><span style="float:right;cursor:pointer;" onclick="javascript:Promotion.removeRestriction('restriction_8');"><?php echo $this->translate('close'); ?></span></div>
                        <div style="float: left; padding-top: 2px; margin:15px;">
                            <input type="hidden" id="selectedCustomerCerfts" name="selectedCustomerCerfts" />
                            <div style="float:left; font-weight:bold; color:#005A5A; margin-right:10px;"><?php echo $this->translate("userType"); ?>:</div>
                            <?php for($i=1;$i<=6;$i++){
                                 if($i !=2){
                            ?>
                            <div style="float:left; margin-left:20px;"><input type="checkbox" name="certf" id="certf<?php echo $i;?>" value="<?php echo $i;?>" /><?php echo $this->translate("certf".$i);?></div>
                            <?php 
                                 }
                            }
                            ?>
                        </div>
                        
                        <div class="clear"></div>
                    </div>
                    
                    <div  id="restriction_9" style="border:2px solid #629508;margin-left: 20px;margin-bottom: 20px;margin-right: 20px;display:none;" >
                        <div style="font-size:12px;color:#005A5A;"><span style="float:right;cursor:pointer;" onclick="javascript:Promotion.removeRestriction('restriction_9');"><?php echo $this->translate('close'); ?></span></div>
                        <div style="float: left; padding-top: 2px; margin:15px;">
                            <input type="hidden" id="selectedCustomerRanks" name="selectedCustomerRanks" />
                            <div style="float:left; font-weight:bold; color:#005A5A; margin-right:10px;"><?php echo $this->translate("customerRank"); ?>:</div>
                            <?php foreach(CustomerConstant::getCustomerRankList() as $key=>$rank){ ?>
                                 <div style="float:left; margin-left:20px;"><input type="checkbox" name="rank" id="rank<?php echo $key;?>" value="<?php echo $key;?>" /><?php echo $rank;?></div>
                            <?php     
                            }
                            ?>
                        </div>
                        
                        <div class="clear"></div>
                    </div>
                    
                </div>
            </div>


            <div class="centerbig_right_nav" id="right_content_div2" style="display:none">
                <div class="form_content">
                    <div class="form_line_div">
                        <div class="form_element">
                            <select id="selectAction" name="selectAction" onchange="javascript:Promotion.changeAction();">
                                <?php foreach($this->actiontype as $key => $value) { ?>
                                <option  value="<?php echo $key; ?>"><?php echo $value; ?></option>
                                <?php } ?>
                            </select>
                            <input type="button" name="AddAction" value="<?php echo $this->translate("addAction"); ?>" onclick="javascript:Promotion.addProductAction();"/>
                            <div class="form_element_error" id="action_show_error"></div>
                        </div>
                    </div>
                </div>
                <div class='clear'></div>
                <div style="margin-left:20px;font-size:12px;">
                    <table cellspacing="0" cellpadding="0">
                        <tbody id="actions_tbody"></tbody>
                    </table>
                </div>
            </div>
        </form>
    </div>
    <div class='clear'></div>
</div>
<div class='clear'></div>
<div id="searchDialog"></div>
